package com.neuedu.common.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MyBatisUtils {

    private static SqlSessionFactory  factory = null;

    /**
     * 获取工厂类
     * @return
     * @throws IOException
     */
    public synchronized static SqlSessionFactory getFactory(String resource) throws IOException {

        if(factory == null){
            InputStream inputStream = Resources.getResourceAsStream(resource);
            factory = new SqlSessionFactoryBuilder().build(inputStream);
        }

        return factory;
    }




}
